package fy.uap.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import fy.config.FyConfig;
import fy.util.DBUtil;

public class ContentMapping {

	/*	private String cvenbankSelect;// 银行

	private String couttypeSelect;// 物流方式

	private String cmoneytypeSelect;// 币种

	private String companyTypeSelect;// 公司类型

	private String aptitudeClassSelect;// 供应商资质类别

	public String getAptitudeClassSelect() {
		return aptitudeClassSelect;
	}

	public void querySelectOption(Connection conn) throws Exception {

		if (cvenbankSelect == null || couttypeSelect == null
				|| cmoneytypeSelect == null || companyTypeSelect == null) {
			Statement stat = null;
			try {
				stat = conn.createStatement();
				queryCvenbankSelectOption(stat);
				queryCouttypeSelectOption(stat);
				queryMoneyTypeSelectOption(stat);
				queryCompanySelectOption(stat);
//				try {
//					queryAptitudeClassSelectOption(stat);
//					// queryCompanyTypeSelectOption(stat);
//				} catch (Exception e) {
//					
//				}
			} finally {
				DBUtil.close(stat);
			}
		}
	}*/

	Connection conn = null;
	PreparedStatement pst = null;

//银行ID
	public String queryCvenbankSelectOption(String banktypename) throws Exception {
		String pk_banktype=null;
		ResultSet rs = null;
		conn = DBUtil.connect(FyConfig.getUAP_DB_CONFIG());
		try {
			pst = conn.prepareStatement("select b.pk_banktype from bd_banktype b where (b.dr='0' or b.dr is null) and b.banktypename=?");
		pst.setString(1, banktypename);
			rs=pst.executeQuery();
			while (rs.next()) {
				pk_banktype = rs.getString(1);
			}
		} finally {
			DBUtil.close(rs);
			DBUtil.close(pst);
		}
		return pk_banktype;
	}
//物流方式
	public String queryCouttypeSelectOption(String sendname) throws Exception {
	String pk_sendtype=null;
	ResultSet rs = null;
	conn = DBUtil.connect(FyConfig.getUAP_DB_CONFIG());
	try {
		pst = conn.prepareStatement("select s.pk_sendtype from bd_sendtype s where (s.dr='0' or s.dr is null) AND s.sendname=?");
	pst.setString(1, sendname);
		rs=pst.executeQuery();
		while (rs.next()) {
			pk_sendtype = rs.getString(1);
		}
	} finally {
		DBUtil.close(rs);
		DBUtil.close(pst);
	}
	
	
	return pk_sendtype;
}
//币种
	public String queryMoneyTypeSelectOption(String currtypename) throws Exception {
	String pk_currtype=null;
	ResultSet rs = null;
	conn = DBUtil.connect(FyConfig.getUAP_DB_CONFIG());
	try {
		pst = conn.prepareStatement("select c.pk_currtype from bd_currtype c where (c.dr='0' or c.dr is null) and c.currtypename=?");
	pst.setString(1, currtypename);
		rs=pst.executeQuery();
		while (rs.next()) {
			pk_currtype = rs.getString(1);
		}
	} finally {
		DBUtil.close(rs);
		DBUtil.close(pst);
	}
	return pk_currtype;
}
//公司类型
	public String queryCompanyTypeSelectOption(String docname) throws Exception {
	String pk_defdoc=null;
	ResultSet rs = null;
	conn = DBUtil.connect(FyConfig.getUAP_DB_CONFIG());
	try {
		pst = conn.prepareStatement("select pk_defdoc from bd_defdoc where (pk_defdoclist = '0001ORGCORP000000002' and (pk_corp = '0001' or pk_corp = '0001')) and (sealflag is null or sealflag <> 'Y') and (pk_defdoc1 is null) AND docname=? order by doccode ");
	pst.setString(1, docname);
		rs=pst.executeQuery();
		while (rs.next()) {
			pk_defdoc = rs.getString(1);
		}
	} finally {
		DBUtil.close(rs);
		DBUtil.close(pst);
	}
	return pk_defdoc;
}
	//物料类别pk_invclass
		public String querypk_invclassTypeSelectOption(String cinvclassname) throws Exception {
		String pk_invclass=null;
		ResultSet rs = null;
		conn = DBUtil.connect(FyConfig.getUAP_DB_CONFIG());
		try {
			pst = conn.prepareStatement("SELECT pk_invclass FROM fy_supplier_invclass f WHERE cinvclassname=?");
		pst.setString(1, cinvclassname);
			rs=pst.executeQuery();
			while (rs.next()) {
				pk_invclass = rs.getString(1);
			}
		} finally {
			DBUtil.close(rs);
			DBUtil.close(pst);
		}
		return pk_invclass;
	}
		//getUapAccountID
		public String getUapAccountID(String unitname) {
			//System.out.println("11111111");
			String pk_corp = null;
			Connection conns;
			PreparedStatement pst = null;
			ResultSet rs = null;
			try {
				conns = DBUtil.connect(FyConfig.getUAP_DB_CONFIG());
					pst = conns
							.prepareStatement("select  pk_corp  from bd_corp where unitname=?");
					pst.setString(1,unitname);
					rs = pst.executeQuery();
					while (rs.next()) {
						pk_corp = rs.getString(1);
						//System.out.println(pk_corp);
					}
			} catch (Exception e) {
				e.printStackTrace();
			} finally {
				DBUtil.close(rs);
				DBUtil.close(pst);
			}
			return pk_corp;
		}
}
